const {app, BrowserWindow, Menu} = require('electron');
const path = require('path');

//Create native application menus and context menus.
//https://www.electronjs.org/docs/latest/api/menu

app.on('ready', () => {
  let win = new BrowserWindow({
    //https://www.electronjs.org/docs/latest/api/browser-window#new-browserwindowoptions
    width: 802,
    height: 550,

    webPreferences: {
      nodeIntegration: true,
      // contextIsolation: true,
      // enableRemoteModule: false,
      // devTools: true
    }
  });
  const nullOrMenu = Menu.getApplicationMenu();

  //todo
  //  Note: The returned Menu instance doesn't support dynamic addition or removal of menu items. Instance properties can still be dynamically modified.
  //  意思大概是(?)你不能主动修改这个返回的对象, 但这个返回的对象会及时更新(通过其它api,比如menu.append,我们无需重复再通过getApplicationMenu, 之前拿到的那个实例对象就银镜更新了)

  console.log('nullOrMenu:',nullOrMenu);
  /*
    nullOrMenu: <ref *1> EventEmitter {
      insertItem: [Function: insertItem],
      insertCheckItem: [Function: insertCheckItem],
      insertRadioItem: [Function: insertRadioItem],
      insertSeparator: [Function: insertSeparator],
      insertSubMenu: [Function: insertSubMenu],
      setIcon: [Function: setIcon],
      setSublabel: [Function: setSublabel],
      setToolTip: [Function: setToolTip],
      setRole: [Function: setRole],
      clear: [Function: clear],
      getIndexOfCommandId: [Function: getIndexOfCommandId],
      getItemCount: [Function: getItemCount],
      getCommandIdAt: [Function: getCommandIdAt],
      getLabelAt: [Function: getLabelAt],
      getSublabelAt: [Function: getSublabelAt],
      getToolTipAt: [Function: getToolTipAt],
      isItemCheckedAt: [Function: isItemCheckedAt],
      isEnabledAt: [Function: isEnabledAt],
      worksWhenHiddenAt: [Function: worksWhenHiddenAt],
      isVisibleAt: [Function: isVisibleAt],
      popupAt: [Function: popupAt],
      closePopupAt: [Function: closePopupAt],
      commandsMap: {
        '2': MenuItem {
          role: 'filemenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'File',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 2,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        '12': MenuItem {
          role: 'editmenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'Edit',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 12,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        '22': MenuItem {
          role: 'viewmenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'View',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 22,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        '26': MenuItem {
          role: 'windowmenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'Window',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 26,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        '31': MenuItem {
          role: 'help',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'Help',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 31,
          click: [Function (anonymous)],
          menu: [Circular *1]
        }
      },
      groupsMap: {},
      items: [
        MenuItem {
          role: 'filemenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'File',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 2,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        MenuItem {
          role: 'editmenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'Edit',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 12,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        MenuItem {
          role: 'viewmenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'View',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 22,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        MenuItem {
          role: 'windowmenu',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'Window',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 26,
          click: [Function (anonymous)],
          menu: [Circular *1]
        },
        MenuItem {
          role: 'help',
          submenu: [EventEmitter],
          type: 'submenu',
          accelerator: null,
          icon: null,
          label: 'Help',
          sublabel: '',
          toolTip: '',
          enabled: true,
          visible: true,
          checked: false,
          acceleratorWorksWhenHidden: true,
          registerAccelerator: true,
          commandId: 31,
          click: [Function (anonymous)],
          menu: [Circular *1]
        }
      ]
    }
  */


  win.loadFile(path.resolve(__dirname, 'index.html'))
});

